﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMSROUTER.Business;

namespace SMSROUTER.UI.ManageSys
{
    public partial class SysLogManagement : BasePage
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            pagingtop.PagingChange += new EventHandler(paging_PagingChange);
            pagingbottom.PagingChange += new EventHandler(paging_PagingChange);
        }

        void paging_PagingChange(object sender, EventArgs e)
        {
            pagingtop.PagingChange -= new EventHandler(paging_PagingChange);
            pagingbottom.PagingChange -= new EventHandler(paging_PagingChange);
            pagingtop.CurrentPage = (sender as UserControl.ucPaging).CurrentPage;
            pagingbottom.CurrentPage = (sender as UserControl.ucPaging).CurrentPage;
            BindGridData();
            pagingtop.Visible = pagingbottom.Visible = (sender as UserControl.ucPaging).TotalPage > 1;
            pagingtop.PagingChange += new EventHandler(paging_PagingChange);
            pagingbottom.PagingChange += new EventHandler(paging_PagingChange);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pagingtop.CurrentPage = pagingbottom.CurrentPage = 1;
                pagingtop.PageSize = pagingbottom.PageSize = PageSize;
                pagingtop.PageDisplay = pagingbottom.PageDisplay = 6;
                BindGridData();
            }
        }

        private void BindGridData()
        {
            int currentPage = pagingtop.CurrentPage;
            int pageSize = pagingtop.PageSize;
            int totalRow = 0;
            grvData.DataSource = SysLog.Paging(currentPage, pageSize, ref totalRow);
            pagingtop.TotalRecord = pagingbottom.TotalRecord = totalRow;
            pagingtop.Visible = pagingbottom.Visible = pagingtop.TotalPage > 1;
            grvData.DataBind();
            ltrInfo.Text = "Total: " + pagingtop.TotalPage + " pages /" + totalRow + " records";
        }
    }
}